#include <iostream>
#include <vector>
using namespace std;

#define MAX 20
int n, m;
int countNum = 0;

struct path
{
    int x, y;
};

vector<path> Path;

void f(int x, int y)
{
    if (x == m && y == n)
    {
        countNum++;
        for (path tmp : Path)
            cout << "(" << tmp.x << "," << tmp.y << ") ";
        cout << endl;
        return;
    }
    // 越界
    else if (x > m || y > n || y < 1)
        return;
    else
    {
        // 斜上
        Path.push_back({x + 1, y + 2});
        f(x + 1, y + 2);
        Path.pop_back();

        // 右上
        Path.push_back({x + 2, y + 1});
        f(x + 2, y + 1);
        Path.pop_back();

        // 右下
        Path.push_back({x + 2, y - 1});
        f(x + 2, y - 1);
        Path.pop_back();

        // 斜下
        Path.push_back({x + 1, y - 2});
        f(x + 1, y - 2);
        Path.pop_back();
    }
}

int main()
{
    cout << "请输入棋盘大小:MxN" << endl;
    cin >> m >> n;
    Path.push_back({1, 1});
    f(1, 1);

    cout << "有" << countNum << "条路径" << endl;
    return 0;
}